{% extends 'generic/object_detail.html' %}
{% load helpers %}

{% block extra_breadcrumbs %}
                {% if object.vrf %}
                    <li><a href="{% url 'ipam:vrf' pk=object.vrf.pk %}">{{ object.vrf }}</a></li>
                {% endif %}
{% endblock extra_breadcrumbs %}

{% block extra_buttons %}
        {% if perms.ipam.add_prefix and active_tab == 'prefixes' and first_available_prefix %}
            <a href="{% url 'ipam:prefix_add' %}?prefix={{ first_available_prefix }}&vrf={{ object.vrf.pk }}&site={{ object.site.pk }}&tenant_group={{ object.tenant.group.pk }}&tenant={{ object.tenant.pk }}" class="btn btn-success">
                <i class="mdi mdi-plus-thick" aria-hidden="true"></i> Add Child Prefix
            </a>
        {% endif %}
        {% if perms.ipam.add_ipaddress and active_tab == 'ip-addresses' and first_available_ip %}
            <a href="{% url 'ipam:ipaddress_add' %}?address={{ first_available_ip }}&vrf={{ object.vrf.pk }}&tenant_group={{ object.tenant.group.pk }}&tenant={{ object.tenant.pk }}" class="btn btn-success">
                <span class="mdi mdi-plus-thick" aria-hidden="true"></span>
                Add an IP Address
            </a>
        {% endif %}
{% endblock extra_buttons %}

{% block panel_buttons %}
    {% include 'ipam/inc/toggle_available.html' %}
{% endblock panel_buttons %}

{% block extra_nav_tabs %}
        <li role="presentation"{% if active_tab == 'prefixes' %} class="active"{% endif %}>
            <a href="{% url 'ipam:prefix_prefixes' pk=object.pk %}">Child Prefixes <span class="badge">{{ object.get_child_prefixes.count }}</span></a>
        </li>
        {% if perms.ipam.view_ipaddress and object.status.slug != 'container' %}
            <li role="presentation"{% if active_tab == 'ip-addresses' %} class="active"{% endif %}>
                <a href="{% url 'ipam:prefix_ipaddresses' pk=object.pk %}">IP Addresses <span class="badge">{{ object.get_child_ips.count }}</span></a>
            </li>
        {% endif %}
{% endblock extra_nav_tabs %}

{% block content_left_page %}
            <div class="panel panel-default">
                <div class="panel-heading">
                    <strong>Prefix</strong>
                </div>
                <table class="table table-hover panel-body attr-table">
                    <tr>
                        <td>Family</td>
                        <td>IPv{{ object.family }}</td>
                    </tr>
                    <tr>
                        <td>VRF</td>
                        <td>
                            {% if object.vrf %}
                                <a href="{% url 'ipam:vrf' pk=object.vrf.pk %}">{{ object.vrf }}</a> ({{ object.vrf.rd }})
                            {% else %}
                                <span>Global</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Tenant</td>
                        <td>
                            {% if object.tenant %}
                                {% if object.tenant.group %}
                                    <a href="{{ object.tenant.group.get_absolute_url }}">{{ object.tenant.group }}</a> /
                                {% endif %}
                                <a href="{{ object.tenant.get_absolute_url }}">{{ object.tenant }}</a>
                            {% else %}
                                <span class="text-muted">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Aggregate</td>
                        <td>
                            {% if aggregate %}
                                <a href="{% url 'ipam:aggregate' pk=aggregate.pk %}">{{ aggregate.prefix }}</a> ({{ aggregate.rir }})
                            {% else %}
                                <span class="text-warning">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Site</td>
                        <td>
                            {% if object.site %}
                                {% if object.site.region %}
                                    <a href="{{ object.site.region.get_absolute_url }}">{{ object.site.region }}</a> /
                                {% endif %}
                                <a href="{% url 'dcim:site' slug=object.site.slug %}">{{ object.site }}</a>
                            {% else %}
                                <span class="text-muted">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>VLAN</td>
                        <td>
                            {% if object.vlan %}
                                {% if object.vlan.group %}
                                    <a href="{{ object.vlan.group.get_absolute_url }}">{{ object.vlan.group }}</a> /
                                {% endif %}
                                <a href="{% url 'ipam:vlan' pk=object.vlan.pk %}">{{ object.vlan.display }}</a>
                            {% else %}
                                <span class="text-muted">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Status</td>
                        <td>
                            <span class="label" style="color: {{ object.status.color|fgcolor }}; background-color: #{{ object.status.color }}">{{ object.get_status_display }}</span>
                        </td>
                    </tr>
                    <tr>
                        <td>Role</td>
                        <td>
                            {% if object.role %}
                                <a href="{{ object.role.get_absolute_url }}">{{ object.role }}</a>
                            {% else %}
                                <span class="text-muted">None</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Description</td>
                        <td>{{ object.description|placeholder }}</td>
                    </tr>
                    <tr>
                        <td>Is a pool</td>
                        <td>
                            {% if object.is_pool %}
                                <i class="mdi mdi-check-bold text-success" title="Yes"></i>
                            {% else %}
                                <i class="mdi mdi-close-thick text-danger" title="No"></i>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>Utilization</td>
                        <td>{% utilization_graph object.get_utilization %}</td>
                    </tr>
                </table>
            </div>
{% endblock content_left_page %}

{% block content_right_page %}
            {% if duplicate_prefix_table.rows %}
                {% include 'panel_table.html' with table=duplicate_prefix_table heading='Duplicate Prefixes' panel_class='danger' %}
            {% endif %}
            {% include 'panel_table.html' with table=parent_prefix_table heading='Parent Prefixes' panel_class='default' %}
{% endblock content_right_page %}
